package main

import (
	"context"
	"net"

	pb "gitee.com/hlwqds/go-project/grpc-demo/proto"
	"gitee.com/hlwqds/go-project/grpc-demo/server/cmd"
	"google.golang.org/grpc"
)

type GreeterServer struct{}

func (s *GreeterServer) SayHello(ctx context.Context, r *pb.HelloRequest) (*pb.HelloReply, error) {
	return &pb.HelloReply{Message: "hello, world"}, nil
}

func (s *GreeterServer) SayList(r *pb.HelloRequest, stream pb.Greeter_SayListServer) error {
	for n := 0; n <= 6; n++ {
		_ = stream.Send(&pb.HelloReply{Message: "hello.list"})
	}

	return nil
}

func main() {
	cmd.Execute()

	server := grpc.NewServer()
	pb.RegisterGreeterServer(server, &GreeterServer{})

	lis, _ := net.Listen("tcp", ":"+cmd.Port)
	defer lis.Close()
	server.Serve(lis)
}
